/*
**      Newton Developer Technical Support Sample Code
**
**     	ListPicker,  The listPicker that uses a user defined soup and 
**		allows for new entries to be added.
**
**      by Stephen Harris, Newton Developer Technical Support
**
**      Copyright  1993-1996 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
*/

//  This sample demonstates the use of the protoListPicker and a user defined soup and give the
//  user the option to add new items to the soup.

// the app stuff
constant kAppTitle := "The List Picker";

//--------------

// Soup stuff
constant kSoupName := kPackageName;
Constant kSoupIndexes := '[{structure: slot,path: first, type: string}];

// for listPicker query
constant kQuerySpec := '{type: index, indexpath: first};

// used by the regUnionSoup function
DefConst('kSoupDef, {
	name: kSoupName,
	username: kAppName,
	ownerApp: kAppSymbol,
	userDescr: "The user soup for the ListPicker sample",
	indexes: kSoupIndexes
}) ;

//--------------


// Random  entry generator.
DefConst('kCanonicalEntry,
   {
		first: nil,
		second: nil,

	});


DefConst('kRandomDataGeneratorFunc, func()
	begin
		local item := clone(kCanonicalEntry);

		item.first := Capitalize(GetRandomWord(4, 12));
		item.second := Capitalize(GetRandomWord(4, 12));
		item;
	end);
		
//--------------

// DeleteScript->  this only gets called when your app is deleted and not
// when the card is removed.
SetPartFrameSlot('DeletionScript, func()
	begin
		//Remove the soup from the stores
		foreach store in GetStores() do 
		begin
			local theSoup := store:GetSoup(kSoupName);
			if theSoup then
			   theSoup:RemoveFromStore();
		end;
	end
);


// Install/Remove Scripts

InstallScript := func(part)
begin	
	RegUnionSoup(kAppSymbol, kSoupDef) ;
end;

RemoveScript := func(part)
begin
	// unregister autocreation of soup
	UnRegUnionSoup(kSoupName, kAppSymbol);
end;